var express = require('express');
var router = express.Router();
/*
/!*

var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
//定义schema
var schema = buildSchema(`
    type Conf{
        key: String
        value: String
    }
    type Query {
        user:User
    }
`);
//定义服务端数据
var root= {
    user: {
        name: 'zhaiqianfeng',
        sex: '男',
        intro: '博主，专注于Linux,Java,nodeJs,Web前端:Html5,JavaScript,CSS3'
    }
};
router.use('/graphql', graphqlHTTP({
    schema: schema,
    rootValue: root,
    graphiql: true, //启用GraphiQL
}));
*!/

var {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString
} = require( 'graphql');

var schema = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'RootQueryType',
        fields: {
            hello: {
                type: GraphQLString,
                resolve() {
                    return 'world';
                }
            }
        }
    })
});

graphql(schema, query).then(result => {

    // Prints
    // {
    //   errors: [
    //     { message: 'Cannot query field boyhowdy on RootQueryType',
    //       locations: [ { line: 1, column: 3 } ] }
    //   ]
    // }
    console.log(result);

});

router.use('/graphql', graphqlHTTP({
    schema: schema,
    graphiql: true, //启用GraphiQL
}));
*/

module.exports = router;